﻿using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

namespace haimian
{
    public static class UCSTools
    {

        /// <summary>
        /// 获取当前UCS
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <returns>返回当前UCS的Id</returns>
        public static ObjectId GetCurrentUCS(this Database db)
        {
            var trans = db.TransactionManager;
            //打开UCS表
            UcsTable ut = (UcsTable)trans.GetObject(db.UcsTableId, OpenMode.ForRead);
            //打开当前活动的视口
            ViewportTableRecord vtr = (ViewportTableRecord)trans.GetObject(db.CurrentViewportTableRecordId, OpenMode.ForRead);
            //返回当前UCS的ObjectId
            return vtr.UcsName;
        }
    }
}
